﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BOHVote.BLL;
using Microsoft.Reporting.WebForms;
using BOHVote.Common;

namespace BOH.Information.Report
{
    public partial class GovrenApplyListReport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string  ApplyPeriod = string.Empty;
            string GovrenID = string.Empty;
            string GovrenName = string.Empty;
            if (!IsPostBack)
            {
                GovrenID = Request.QueryString["GovrenID"];
                ApplyPeriod = Request.QueryString["ApplyPeriod"];
                GovrenName = UnitClass.GetGovernName(GovrenID);
                this.Title = common.getAppSetting("AppName");
                string strCount = string.Empty;
                XSD.PersonalInfo xsd = BindReport(GovrenID, ApplyPeriod, out strCount);
                ReportViewBind(xsd, GovrenName, ApplyPeriod + "年度", strCount);
            }
        }

        public XSD.PersonalInfo BindReport(string GovernID, string ApplyPeriod,out string RecordCount)
        {
            string strGovernName = string.Empty;
            string strCount = string.Empty;
            XSD.PersonalInfo personalXSD = new BOH.XSD.PersonalInfo();
            DataSet dst = ApplyClass.getApplyInfo("", "", GovernID, ApplyPeriod);
            int i = 0;
            strCount = dst.Tables[0].Rows.Count.ToString();
            RecordCount = strCount;
            foreach (DataRow dr in dst.Tables[0].Rows)
            {
                DataRow drNew = personalXSD.Tables["PersonalInfo"].NewRow();
                drNew["NO"] = ++i;
                drNew["ApplyName"] = dr["Apply_Name"].ToString();
                drNew["UnitGovernName"] = dr["UnitGovernName"].ToString();
                drNew["ApplyPeriod"] = dr["ApplyPeriodID"].ToString();
                drNew["Gender"] = dr["Gender"].ToString();
                if (!string.IsNullOrEmpty(dr["Birthday"].ToString()))
                    drNew["Birthday"] = Convert.ToDateTime(dr["Birthday"].ToString()).ToString("yyyy-MM"); //common.changeDateFormatToDate(dr["Birthday"].ToString()).ToString("yyyy-MM-dd");
                else
                    drNew["Birthday"] = "-";

                drNew["EducationLevel"] = dr["EducationLevel"].ToString();
                drNew["IDCard"] = dr["IDCard"].ToString();
                drNew["School"] = dr["School"].ToString();

                if (!string.IsNullOrEmpty(dr["GraduationDate"].ToString()))
                    drNew["GraduationDate"] = Convert.ToDateTime(dr["GraduationDate"].ToString()).ToString("yyyy-MM");// common.changeDateFormatToDate(dr["GraduationDate"].ToString()).ToString("yyyy-MM-dd");
                else
                    drNew["GraduationDate"] = "-";

                drNew["CurrentJobRank"] = dr["CurrentJobRankID"].ToString();
                drNew["ApplyType"] = dr["ApplyType"].ToString();
                drNew["SpecialityID"] = dr["SpecialityID"].ToString();
                drNew["JobRankID"] = dr["JobRankID"].ToString();
                drNew["SubjectID"] = dr["SubjectID"].ToString();

                if (!string.IsNullOrEmpty(dr["JobDate"].ToString()))
                    drNew["JobDate"] = Convert.ToDateTime(dr["JobDate"].ToString()).ToString("yyyy-MM");
                else
                    drNew["JobDate"] = "-";

                // common.changeDateFormatToDate(dr["JobDate"].ToString()).ToString("yyyy-MM-dd");
                if (!string.IsNullOrEmpty(dr["ConversionDate"].ToString()))
                    drNew["ConversionDate"] = Convert.ToDateTime(dr["ConversionDate"].ToString()).ToString("yyyy-MM");
                else
                    drNew["ConversionDate"] = "-";

                drNew["JobTerm"] = dr["JobTerm"].ToString();
                drNew["FixedJob"] = dr["FixedJob"].ToString();
                drNew["ForeignLanguageName"] = dr["ForeignLanguageName"].ToString();
                drNew["ForeignLanguageResult"] = dr["ForeignLanguageResult"].ToString();
                drNew["PoliticsResult"] = dr["PoliticsResult"].ToString();
                drNew["JobResult"] = dr["JobResult"].ToString();
                drNew["ComputerResult"] = dr["ComputerResult"].ToString();
                drNew["ApplyPrintID"] = dr["ApplyPrintID"].ToString();

                personalXSD.Tables["PersonalInfo"].Rows.Add(drNew);

            }

            return personalXSD;
        }

        public void ReportViewBind(XSD.PersonalInfo personalXSD, string GovrenName, string ApplyPeriod,string Count)
        {
            ReportDataSource datasource = new ReportDataSource("PersonalInfo_PersonalInfo", personalXSD.Tables["PersonalInfo"]);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(datasource);
            ReportParameter[] param = new ReportParameter[3];
            param[0] = new ReportParameter("GovrenName", GovrenName);
            param[1] = new ReportParameter("ApplyPeriod", ApplyPeriod);
            param[2] = new ReportParameter("ApplyCount", Count);
            ReportViewer1.LocalReport.SetParameters(param);
            ReportViewer1.LocalReport.Refresh();
        }
    }
}
